//
//  NSString+WJDateString.m
//  天气
//
//  Created by dllo on 16/8/23.
//  Copyright © 2016年 WJ. All rights reserved.
//

#import "NSString+WJDateString.h"

@implementation NSString (WJDateString)

+ (NSString *)getWeekDayFordate:(long long)date
{
    NSArray *weekday = [NSArray arrayWithObjects: [NSNull null], @"星期日", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
    
    NSDate *newDate = [NSDate dateWithTimeIntervalSince1970:date];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [calendar components:NSWeekdayCalendarUnit fromDate:newDate];
    
    NSString *weekStr = [weekday objectAtIndex:components.weekday];
    return weekStr;
}

+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Beijing"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}

+ (NSString *)getZhouJiForDate:(NSString *)date
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *destDate = [dateFormatter dateFromString:date];
    return  [self weekdayStringFromDate:destDate];
}







#pragma mark- 获取当前时间
+ (NSString *)getCurrentTime{
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString * dateStr = [formatter stringFromDate:[NSDate date]];
    return dateStr;
}

+ (NSString *)getCurrentDay{
    NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSString * dateStr = [formatter stringFromDate:[NSDate date]];
    return dateStr;
    
}

+ (NSDate *)getStartOfToday{
    
    NSDateFormatter * formatter1 = [[NSDateFormatter alloc]init];
    [formatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString * day = [self getCurrentDay];
    NSString * newstr = [NSString stringWithFormat:@"%@ 00:00:01", day];
    NSDate * date = [formatter1 dateFromString:newstr];
    return date;
}

+ (NSDate *)getEndOfToday{
    
    NSDateFormatter * formatter1 = [[NSDateFormatter alloc]init];
    [formatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString * day = [self getCurrentDay];
    NSString * newstr = [NSString stringWithFormat:@"%@ 23:59:59", day];
    NSDate * date = [formatter1 dateFromString:newstr];
    return date;
}

@end
